package com.stylefeng.guns.modular.assetRegistration.service.impl;

import com.stylefeng.guns.core.exception.GunsException;
import com.stylefeng.guns.modular.system.model.AssetRegistration;
import com.stylefeng.guns.modular.system.dao.AssetRegistrationMapper;
import com.stylefeng.guns.modular.assetRegistration.service.IAssetRegistrationService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * <p>
 *  固定资产服务实现类
 * </p>
 *
 * @author stylefeng123
 * @since 2018-07-19
 */
@Service
public class AssetRegistrationServiceImpl extends ServiceImpl<AssetRegistrationMapper, AssetRegistration> implements IAssetRegistrationService {

    /**
     * 描述:导出固定资产表
     * 创建人: laoyu
     * 日期: 2018/8/13 0013
     * 时间: 上午 11:43
     */
    @Override
    public Map<String, Object> load(List<AssetRegistration> assetRegistrationList) throws GunsException {
        AtomicInteger id=new AtomicInteger(1);
        List<Map<String,Object>> maplist = new ArrayList<>();
        double total = 0;
        for (AssetRegistration assetRegistration: assetRegistrationList){
            Map<String,Object> map  = new HashMap<>();
            map.put("numb",id.incrementAndGet());
            map.put("coding",assetRegistration.getCoding());
            map.put("name",assetRegistration.getName());
            map.put("specification",assetRegistration.getSpecification());
            map.put("unit",assetRegistration.getUnit());
            map.put("quantity",assetRegistration.getQuantity());
            map.put("unitPrice",assetRegistration.getUnitPrice());
            map.put("amount",assetRegistration.getAmount());
            map.put("user",assetRegistration.getUser());
            map.put("saveLocation",assetRegistration.getSaveLocation());
            map.put("purchaseTime",assetRegistration.getPurchaseTime());
            map.put("remarks",assetRegistration.getRemarks());
            maplist.add(map);
            total += assetRegistration.getAmount();
        }
        Map<String,Object> loadMap = new HashMap<>();
        loadMap.put("maplist",maplist);
        loadMap.put("name","固定资产备查登记表");
        loadMap.put("total",total);

        return loadMap;
    }
}
